package com.ycsd.invest.order.business.formplugin;

import kd.bd.sbd.consts.OperationKeyConst;
import kd.bos.dataentity.OperateOption;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.operate.result.OperationResult;
import kd.bos.form.control.Control;
import kd.bos.form.control.events.BeforeClickEvent;
import kd.bos.form.plugin.AbstractMobFormPlugin;
import kd.bos.servicehelper.operation.OperationServiceHelper;

import java.util.EventObject;

/**
 * @Descrіption: 移动表单
 * @Author: yn
 * @Date: 2025/6/20 14:18
 */
public class TestMobFormPlugin extends AbstractMobFormPlugin {

    @Override
    public void registerListener(EventObject e) {
        this.addClickListeners("bar_submit", "bar_save");
    }

    @Override
    public void beforeClick(BeforeClickEvent evt) {
        evt.setCancel(true);
        // 如果是确定按钮，则取到人员的数据，返回给父页面
        Control control = (Control) evt.getSource();
        if ("bar_submit".equalsIgnoreCase(control.getKey())) {
            this.getView().showMessage("submit");
            this.getView().invokeOperation(OperationKeyConst.OP_SUBMIT);
        } else if ("bar_save".equals(control.getKey())) {
            this.getView().showMessage("save");
//            OperationResult operationResult = this.getView().invokeOperation(OperationKeyConst.OP_SAVE);
            OperationResult result = OperationServiceHelper.executeOperate("save",
                    "ycsd_study_form", new DynamicObject[] { this.getModel().getDataEntity() },
                    OperateOption.create());

            System.out.println(result);
        }

    }
}
